package com.cupdata.zicon.proxy;

import org.junit.Test;

import java.lang.reflect.Proxy;

/**
 * 代理模式测试类
 */
public class ProxyTest {

    @Test
    public void proxyTest01(){
        //静态代理
        RealSubject realSubject = new RealSubject();
        SubjectProxy subjectProxy = new SubjectProxy(realSubject);
        subjectProxy.operation();
    }

    @Test
    public void proxyTest02(){
        RealSubject realSubject = new RealSubject();
        ObjectProxyJDK objectProxyJDK = new ObjectProxyJDK(realSubject);
        Subject subject = (Subject)Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{Subject.class}, objectProxyJDK);
        subject.operation();
    }
}
